package com.zhijie.customer.demo;
import java.math.BigDecimal;
import com.google.common.collect.Lists;
import java.time.LocalDate;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhijie.base.customer.entity.Customer;
import com.zhijie.customer.service.ICustomerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("customer")
public class DemoTestController {

    @Autowired
    private ICustomerService customerService;


    @GetMapping("demo")
    public Customer demo(String val) {
        Customer byId = customerService.getById(198112504918016L);
        if (byId != null) {
            System.out.println(byId.toString());
        }
        return byId;
    }

    @GetMapping("update")
    public Customer update(Long id) {
        Customer byId = customerService.getById(198112525516800L);
        byId.setAddress("fsafdsaf");
        customerService.updateById(byId);
        byId = customerService.getById(id);
        return byId;
    }

    @GetMapping("page")
    public Page<Customer> page(Long id) {
        Page<Customer> userPage = new Page<>(1, 3);
        LambdaQueryWrapper<Customer> customQueryWrapper = Wrappers.lambdaQuery();
        customQueryWrapper.like(Customer::getName, "浙江");
        customQueryWrapper.orderByDesc(Customer::getName);
        Page<Customer> page = customerService.page(userPage, customQueryWrapper);
        return page;
    }

    @GetMapping("select")
    public Customer select(Long id) {
        Customer byId = customerService.getById(id);
        return byId;
    }

    @GetMapping("select2")
    public Page<Customer> select2(Long id) {
        Page<Customer> userPage = new Page<>(1, 3);
        LambdaQueryWrapper<Customer> customQueryWrapper = Wrappers.lambdaQuery();
        customQueryWrapper.select(Customer::getId, Customer::getName).like(Customer::getName, "浙江");
        userPage = customerService.page(userPage, customQueryWrapper);
        return userPage;
    }

    @GetMapping("select3")
    public Customer select3(Long id) {
        Customer customer = customerService.getAllById(id);
        return customer;
    }
    @GetMapping("select4")
    public Page<Customer> select4(Long id) {
        Page<Customer> userPage = new Page<>(1, 3);
        LambdaQueryWrapper<Customer> customQueryWrapper = Wrappers.lambdaQuery();
        customQueryWrapper.like(StringUtils.isNotBlank("浙江"),Customer::getName, "浙江");
        customQueryWrapper.likeRight(StringUtils.isNotBlank(""),Customer::getAreaCode, "33");
        customQueryWrapper.orderByDesc(Customer::getName);
        Page<Customer> page = customerService.page(userPage, customQueryWrapper);
        return page;
    }
    @PostMapping("demo1")
    public Customer demo1(@RequestBody Customer customer) {
        Customer byId = customerService.getById(1);

        return byId;
    }

    @GetMapping("save")
    public Customer save() {
        Customer customer = new Customer();
        customer.setName("fsdaf");
        customer.setCustomerCode("fdgsdfg");
        customer.setOrganizationCode("gfdhdsfgsdgf");
        customer.setIsPool(false);
        boolean save = customerService.save(customer);


        return customer;
    }
}
